

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="ShanCe">
  <meta name="keywords" content="">
  
    <meta name="description" content="统一返回类1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import jsonfrom enum import Enumfrom django.http import JsonResponse, HttpResponsefrom">
<meta property="og:type" content="article">
<meta property="og:title" content="django统一返回">
<meta property="og:url" content="https://sweetshance.github.io/2024/09/13/django/django%E7%BB%9F%E4%B8%80%E8%BF%94%E5%9B%9E/index.html">
<meta property="og:site_name" content="ShanCe的博客">
<meta property="og:description" content="统一返回类1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import jsonfrom enum import Enumfrom django.http import JsonResponse, HttpResponsefrom">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-09-13T06:11:16.000Z">
<meta property="article:modified_time" content="2024-09-13T06:17:36.288Z">
<meta property="article:author" content="ShanCe">
<meta name="twitter:card" content="summary_large_image">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>django统一返回 - ShanCe的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"sweetshance.github.io","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>ShanCe</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="django统一返回"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        ShanCe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2024-09-13 14:11" pubdate>
          2024年9月13日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          3.5k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          30 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">django统一返回</h1>
            
            
              <div class="markdown-body">
                
                <h3 id="统一返回类"><a href="#统一返回类" class="headerlink" title="统一返回类"></a>统一返回类</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> json<br><span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum<br><span class="hljs-keyword">from</span> django.http <span class="hljs-keyword">import</span> JsonResponse, HttpResponse<br><span class="hljs-keyword">from</span> tools.date_json <span class="hljs-keyword">import</span> DateEncoder<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">ErrorInfo</span>(<span class="hljs-title class_ inherited__">Exception</span>):<br>    code = <span class="hljs-string">&#x27;&#x27;</span><br>    msg = <span class="hljs-string">&#x27;&#x27;</span> <br>    <br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__str__</span>(<span class="hljs-params">self</span>) -&gt; <span class="hljs-built_in">str</span>:<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">f&quot;errorInfo: <span class="hljs-subst">&#123;self.msg&#125;</span>&quot;</span><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">ReturnInfo</span>(<span class="hljs-title class_ inherited__">Enum</span>):<br>    <span class="hljs-comment"># 请求成功</span><br>    code_200 = <span class="hljs-string">&quot;请求成功&quot;</span><br><br>    <span class="hljs-comment"># 缺少参数</span><br>    code_400 = <span class="hljs-string">&quot;缺少参数&quot;</span><br>    <span class="hljs-comment"># 数据不存在</span><br>    code_404 = <span class="hljs-string">&quot;数据不存在&quot;</span><br>    <span class="hljs-comment"># 后台错误</span><br>    code_500 = <span class="hljs-string">&quot;请求报错&quot;</span><br>    <span class="hljs-comment"># 错误</span><br>    code_10001 = <span class="hljs-string">&quot;缺少token&quot;</span><br>    <span class="hljs-comment"># token过期</span><br>    code_10002 = <span class="hljs-string">&quot;token过期&quot;</span><br>    <span class="hljs-comment"># 用户过期</span><br>    code_10003 = <span class="hljs-string">&quot;refreshToken过期&quot;</span><br>    <span class="hljs-comment"># 参数错误</span><br>    code_204 = <span class="hljs-string">&quot;未查询到相关数据&quot;</span><br>    <span class="hljs-comment"># 不支持此类型</span><br>    code_205 = <span class="hljs-string">&#x27;暂不支持此类型&#x27;</span><br>    <span class="hljs-comment"># 请求第三方接口失败</span><br>    code_3001 = <span class="hljs-string">&#x27;请求第三方接口失败&#x27;</span><br>    <span class="hljs-comment"># 请求数据异常</span><br>    code_3002 = <span class="hljs-string">&#x27;请求数据异常&#x27;</span><br>    <span class="hljs-comment"># 次数上线</span><br>    code_206 = <span class="hljs-string">&#x27;请求次数上线&#x27;</span> <br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_msg</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-keyword">return</span> self.value<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">ReturnFormat</span>:<br>    <br><span class="hljs-meta">    @staticmethod</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">return_value</span>(<span class="hljs-params">code: <span class="hljs-built_in">int</span>, data, msg_=<span class="hljs-literal">None</span></span>):<br>        <span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">            code: 返回的code 码</span><br><span class="hljs-string">        &quot;&quot;&quot;</span><br>        msg = msg_ <span class="hljs-keyword">or</span> ReturnInfo[<span class="hljs-string">f&quot;code_<span class="hljs-subst">&#123;code&#125;</span>&quot;</span>].get_msg()<br>        <span class="hljs-keyword">return</span> HttpResponse(json.dumps(&#123;<span class="hljs-string">&quot;code&quot;</span>: code, <span class="hljs-string">&quot;msg&quot;</span>: msg, <span class="hljs-string">&quot;data&quot;</span>: data&#125;, cls=DateEncoder, ensure_ascii=<span class="hljs-literal">False</span>),  content_type=<span class="hljs-string">&quot;application/json&quot;</span>)<br><br><span class="hljs-meta">    @staticmethod</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">raise_value</span>(<span class="hljs-params">code: <span class="hljs-built_in">int</span>, msg=<span class="hljs-literal">None</span></span>):<br>        ErrorInfo.code = code<br>        ErrorInfo.msg = msg <span class="hljs-keyword">or</span> ReturnInfo[<span class="hljs-string">f&quot;code_<span class="hljs-subst">&#123;code&#125;</span>&quot;</span>].get_msg()<br>        <span class="hljs-keyword">raise</span> ErrorInfo<br><br></code></pre></td></tr></table></figure>

<h3 id="装饰器"><a href="#装饰器" class="headerlink" title="装饰器"></a>装饰器</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> json<br><span class="hljs-keyword">import</span> logging<br><span class="hljs-keyword">import</span> os<br><span class="hljs-keyword">import</span> sys<br><span class="hljs-keyword">from</span> pydantic.error_wrappers <span class="hljs-keyword">import</span> ValidationError<br><span class="hljs-keyword">from</span> apps.dataFormat.returnFormat <span class="hljs-keyword">import</span> ErrorInfo, ReturnFormat<br><br><br>error_log = logging.getLogger(<span class="hljs-string">&quot;error&quot;</span>)<br>server_info = logging.getLogger(<span class="hljs-string">&quot;server&quot;</span>)<br><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">random_str</span>(<span class="hljs-params">length=<span class="hljs-number">6</span></span>):<br>    <span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">    随机数长度</span><br><span class="hljs-string">    :param length:</span><br><span class="hljs-string">    :return:</span><br><span class="hljs-string">    &quot;&quot;&quot;</span><br>    date_str = datetime.now().strftime(<span class="hljs-string">&quot;%m%d%H%M%S&quot;</span>)<br>    random_list = [<span class="hljs-built_in">chr</span>(random.choice(<span class="hljs-built_in">list</span>(<span class="hljs-built_in">range</span>(<span class="hljs-number">97</span>, <span class="hljs-number">123</span>)))) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(length)]<br>    <span class="hljs-keyword">return</span> date_str + <span class="hljs-string">&quot;&quot;</span>.join(random_list)<br><br><br><span class="hljs-comment"># 请求接口日志</span><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">write_request</span>(<span class="hljs-params">request</span>):<br>    url = request.META[<span class="hljs-string">&#x27;HTTP_HOST&#x27;</span>] + request.META[<span class="hljs-string">&#x27;PATH_INFO&#x27;</span>] + request.META[<span class="hljs-string">&#x27;QUERY_STRING&#x27;</span>]<br>    request_uuid = request.request_uuid<br>    data = &#123;<br>        <span class="hljs-string">&quot;header&quot;</span>: request.headers,<br>        <span class="hljs-string">&quot;body&quot;</span>: request.body,<br>        <span class="hljs-string">&quot;params&quot;</span>: request.GET,<br>    &#125;<br>    server_info.info(<span class="hljs-string">f&quot;request, url: <span class="hljs-subst">&#123;url&#125;</span>, <span class="hljs-subst">&#123;data&#125;</span>&quot;</span>)<br><br><br><span class="hljs-comment"># 返回接口日志</span><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">write_response</span>(<span class="hljs-params">requets, data: <span class="hljs-built_in">dict</span></span>):<br>    request_uuid = request.request_uuid<br>    server_info.info(<span class="hljs-string">f&quot;response, <span class="hljs-subst">&#123;data&#125;</span>&quot;</span>)<br><br><br><span class="hljs-comment"># 返回类装饰器</span><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">return_info</span>(<span class="hljs-params">func</span>):<br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">wrapper</span>(<span class="hljs-params">self, request</span>):<br>        request.request_uuid = random_str(<span class="hljs-number">6</span>)<br>        write_request(request=request)<br>        <span class="hljs-keyword">try</span>:<br>            res = func(self, request)<br>            write_response(request, res)<br>            <span class="hljs-keyword">return</span> ReturnFormat.return_value(code=<span class="hljs-number">200</span>, data=res, msg_=<span class="hljs-string">&quot;成功&quot;</span>)<br>        <span class="hljs-keyword">except</span> ErrorInfo <span class="hljs-keyword">as</span> e:<br>            error_log.error(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;e&#125;</span>&quot;</span>)<br>            code = e.code<br>            msg = e.msg<br>            write_response(request, &#123;<span class="hljs-string">&quot;code&quot;</span>: code, <span class="hljs-string">&quot;msg&quot;</span>: msg&#125;)<br>            <span class="hljs-keyword">return</span> ReturnFormat.return_value(code=code, data=&#123;&#125;, msg_=msg)<br>        <span class="hljs-comment"># 参数校验</span><br>        <span class="hljs-keyword">except</span> ValidationError <span class="hljs-keyword">as</span> e:<br>            error_log.error(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;e&#125;</span>&quot;</span>)<br>            code = <span class="hljs-number">400</span><br>            data = json.loads(e.json())[<span class="hljs-number">0</span>]<br>            msg = <span class="hljs-string">f&#x27;<span class="hljs-subst">&#123;data.get(<span class="hljs-string">&quot;loc&quot;</span>)&#125;</span> <span class="hljs-subst">&#123;data.get(<span class="hljs-string">&quot;msg&quot;</span>)&#125;</span>&#x27;</span><br>            write_response(request, &#123;<span class="hljs-string">&quot;code&quot;</span>: code, <span class="hljs-string">&quot;msg&quot;</span>: msg&#125;)<br>            <span class="hljs-keyword">return</span> ReturnFormat.return_value(code=code, data=&#123;&#125;, msg_=msg)<br>        <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:<br>            error_log.error(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;e&#125;</span>&quot;</span>)<br>            write_response(request, &#123;<span class="hljs-string">&quot;msg&quot;</span>: e&#125;)<br>            <span class="hljs-comment"># print(type(e), type(e) == ErrorInfo, isinstance(e, ErrorInfo))</span><br>            msg = <span class="hljs-string">&quot;获取数据失败&quot;</span><br>            <span class="hljs-keyword">raise</span>(e)<br>           <br>    <span class="hljs-keyword">return</span> wrapper<br></code></pre></td></tr></table></figure>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>django统一返回</div>
      <div>https://sweetshance.github.io/2024/09/13/django/django统一返回/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>ShanCe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2024年9月13日</div>
        </div>
      
      
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2024/11/06/springBoot%E5%AD%A6%E4%B9%A0/mybatis%E6%89%B9%E9%87%8F%E6%9B%B4%E6%96%B0%E5%92%8C%E6%89%B9%E9%87%8F%E6%8F%92%E5%85%A5%E5%92%8Crepalce%E6%89%B9%E9%87%8F/" title="mybatis批量更新和批量插入和repalce批量">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">mybatis批量更新和批量插入和repalce批量</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2024/09/13/django/django-pydantic%E5%8F%82%E6%95%B0%E6%A0%A1%E9%AA%8C/" title="django+pydantic参数校验">
                        <span class="hidden-mobile">django+pydantic参数校验</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="http://82.157.172.231/" target="_blank" rel="nofollow noopener"><span>无聊</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>ShanCe</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
